package written.test;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

/**
 * @Author: Dang Qi
 * @Date: 2021/4/11  19:25
 * @Description:
 */
public class Baidu {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int i = 0; i < T; i++){
            int a = sc.nextInt(), b = sc.nextInt();
            System.out.println(min(1, a, b, 0, false));
        }


    }
    public static int min(int cur, int a, int b, int deep, boolean findOne){
        if(cur > a && cur > b) return -1;
        if(cur == a || cur == b) {
            if(findOne) return deep;
            int d = min(cur* 2, a, b, deep+1,true);
            d = d != -1 ? d : min(cur * 2+1, a, b, deep+1,true);
            if(d==-1) return deep;
            else return d - deep;
        }else{
            int left = min(cur* 2, a, b, deep+1,false);
            if(left!=-1&&findOne) return left;
            int right = min(cur * 2+1, a, b, deep+1,false);

            if(left!=-1&&right!=-1) return left + right - 2 * deep;
            return  left == -1 ? right : left;
        }

    }
    public static int get2(int n){
        int tmp = n;
        n = n-1;
        n |= n>>1;
        n |= n>>2;
        n |= n>>4;
        n |= n>>8;
        n |= n>>16;
        int ans = 0;
        while (n!=0){
            n >>= 1;
            ans++;
        }
        return  ans;
    }
}
